package com.brzjomo.secretiveworld.client.renderer.entity.model;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;

import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class TestFishModel<T extends Entity> extends EntityModel<T> {
	private final ModelRenderer Body;
	private final ModelRenderer head;
	private final ModelRenderer collection2;
	private final ModelRenderer middle;
	private final ModelRenderer fin_left;
	private final ModelRenderer fin_right;
	private final ModelRenderer collection3;
	private final ModelRenderer after_middle;
	private final ModelRenderer fin;
	private final ModelRenderer tail;

	public TestFishModel() {
		textureWidth = 32;
		textureHeight = 32;

		Body = new ModelRenderer(this);
		Body.setRotationPoint(-0.5F, 22.5F, 1.0F);

		head = new ModelRenderer(this);
		head.setRotationPoint(0.0F, 0.0F, -4.0F);
		Body.addChild(head);
		head.setTextureOffset(0, 0).addBox(-0.5F, 0.5F, -10.0F, 1.0F, 1.0F, 7.0F, 0.0F, false);
		head.setTextureOffset(9, 0).addBox(-1.5F, -0.5F, -3.0F, 3.0F, 2.0F, 1.0F, 0.0F, false);
		head.setTextureOffset(9, 3).addBox(-1.5F, -1.5F, -2.0F, 3.0F, 3.0F, 1.0F, 0.0F, false);
		head.setTextureOffset(0, 19).addBox(-1.5F, -2.5F, -1.0F, 3.0F, 4.0F, 1.0F, 0.0F, false);
		head.setTextureOffset(0, 4).addBox(-0.5F, 1.5F, -2.0F, 1.0F, 1.0F, 2.0F, 0.0F, false);

		collection2 = new ModelRenderer(this);
		collection2.setRotationPoint(0.0F, 0.0F, -4.0F);
		Body.addChild(collection2);

		middle = new ModelRenderer(this);
		middle.setRotationPoint(0.0F, 0.0F, 0.0F);
		collection2.addChild(middle);
		middle.setTextureOffset(9, 1).addBox(-1.5F, -2.5F, 0.0F, 3.0F, 4.0F, 7.0F, 0.0F, false);
		middle.setTextureOffset(0, 8).addBox(-0.5F, 1.5F, 0.0F, 1.0F, 1.0F, 7.0F, 0.0F, false);
		middle.setTextureOffset(0, 8).addBox(-0.5F, -3.5F, 2.0F, 1.0F, 1.0F, 1.0F, 0.0F, false);
		middle.setTextureOffset(4, 11).addBox(-0.5F, -5.5F, 3.0F, 1.0F, 3.0F, 1.0F, 0.0F, false);
		middle.setTextureOffset(0, 10).addBox(-0.5F, -6.5F, 4.0F, 1.0F, 4.0F, 1.0F, 0.0F, false);
		middle.setTextureOffset(9, 12).addBox(-0.5F, -6.5F, 5.0F, 1.0F, 2.0F, 1.0F, 0.0F, false);
		middle.setTextureOffset(4, 8).addBox(-0.5F, -6.5F, 6.0F, 1.0F, 1.0F, 1.0F, 0.0F, false);

		fin_left = new ModelRenderer(this);
		fin_left.setRotationPoint(0.5F, 1.5F, 2.25F);
		middle.addChild(fin_left);
		setRotationAngle(fin_left, 0.0F, -0.3927F, 0.829F);
		fin_left.setTextureOffset(13, 12).addBox(-0.3941F, -0.6756F, -1.0249F, 2.0F, 1.0F, 2.0F, 0.0F, false);
		fin_left.setTextureOffset(22, 0).addBox(1.6059F, -0.6756F, -1.0249F, 1.0F, 1.0F, 1.0F, 0.0F, false);

		fin_right = new ModelRenderer(this);
		fin_right.setRotationPoint(-0.5F, 1.5F, 2.3F);
		middle.addChild(fin_right);
		setRotationAngle(fin_right, 0.0F, -0.3927F, 2.3126F);
		fin_right.setTextureOffset(21, 12).addBox(-0.4864F, -0.3995F, -1.0455F, 2.0F, 1.0F, 2.0F, 0.0F, false);
		fin_right.setTextureOffset(22, 2).addBox(1.5136F, -0.3995F, -1.0455F, 1.0F, 1.0F, 1.0F, 0.0F, false);

		collection3 = new ModelRenderer(this);
		collection3.setRotationPoint(0.0F, -0.5F, 7.0F);
		collection2.addChild(collection3);

		after_middle = new ModelRenderer(this);
		after_middle.setRotationPoint(0.0F, 0.0F, 0.0F);
		collection3.addChild(after_middle);
		after_middle.setTextureOffset(13, 15).addBox(-1.5F, -2.0F, 0.0F, 3.0F, 4.0F, 3.0F, 0.0F, false);
		after_middle.setTextureOffset(22, 16).addBox(-1.5F, -2.0F, 3.0F, 3.0F, 3.0F, 2.0F, 0.0F, false);
		after_middle.setTextureOffset(22, 4).addBox(-1.5F, -1.0F, 5.0F, 3.0F, 2.0F, 1.0F, 0.0F, false);

		fin = new ModelRenderer(this);
		fin.setRotationPoint(0.0F, 2.0F, 2.0F);
		after_middle.addChild(fin);
		setRotationAngle(fin, 0.2182F, 0.0F, 0.0F);
		fin.setTextureOffset(22, 5).addBox(-0.5F, -0.3223F, -1.0742F, 1.0F, 1.0F, 2.0F, 0.0F, false);
		fin.setTextureOffset(19, 12).addBox(-0.5F, 0.6777F, -1.0742F, 1.0F, 1.0F, 1.0F, 0.0F, false);

		tail = new ModelRenderer(this);
		tail.setRotationPoint(0.0F, 0.0F, 6.0F);
		collection3.addChild(tail);
		tail.setTextureOffset(26, 0).addBox(-0.5F, -1.0F, 0.0F, 1.0F, 2.0F, 2.0F, 0.0F, false);
		tail.setTextureOffset(28, 21).addBox(-0.5F, -2.0F, 2.0F, 1.0F, 4.0F, 1.0F, 0.0F, false);
		tail.setTextureOffset(9, 16).addBox(-0.5F, -3.0F, 3.0F, 1.0F, 2.0F, 1.0F, 0.0F, false);
		tail.setTextureOffset(9, 19).addBox(-0.5F, 1.0F, 3.0F, 1.0F, 2.0F, 1.0F, 0.0F, false);
		tail.setTextureOffset(5, 16).addBox(-0.5F, -4.0F, 4.0F, 1.0F, 2.0F, 1.0F, 0.0F, false);
		tail.setTextureOffset(28, 12).addBox(-0.5F, 2.0F, 4.0F, 1.0F, 1.0F, 1.0F, 0.0F, false);
	}

	@Override
	public void setRotationAngles(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw,
			float headPitch) {
		float f = 1.0F;
		float f1 = 1.0F;
		if (!entity.isInWater()) {
			f = 1.3F;
			f1 = 1.7F;
		}

		this.collection2.rotateAngleY = -f * 0.25F * MathHelper.sin(f1 * 0.08F * ageInTicks);
		this.collection3.rotateAngleY = -f * 0.25F * MathHelper.sin(f1 * 0.08F * ageInTicks);
		this.tail.rotateAngleY = -f * 0.25F * MathHelper.sin(f1 * 0.08F * ageInTicks);
		this.fin_left.rotateAngleX = -f * 0.25F * MathHelper.sin(f1 * 0.07F * ageInTicks);
		this.fin_left.rotateAngleY = -f * 0.25F * MathHelper.sin(f1 * 0.1F * ageInTicks);
		this.fin_right.rotateAngleX = -f * 0.25F * MathHelper.sin(f1 * 0.07F * ageInTicks);
		this.fin_right.rotateAngleY = -f * 0.25F * MathHelper.sin(f1 * 0.1F * ageInTicks);
		this.fin.rotateAngleY = -f * 0.25F * MathHelper.sin(f1 * 0.05F * ageInTicks);
	}

	@Override
	public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red,
			float green, float blue, float alpha) {
		Body.render(matrixStack, buffer, packedLight, packedOverlay);
	}

	public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
		modelRenderer.rotateAngleX = x;
		modelRenderer.rotateAngleY = y;
		modelRenderer.rotateAngleZ = z;
	}

	@Override
	public void setLivingAnimations(T entityIn, float limbSwing, float limbSwingAmount, float partialTick) {
		super.setLivingAnimations(entityIn, limbSwing, limbSwingAmount, partialTick);
	}
}